package com.hp.tiger.chapter4;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author XavierDong
 **/
public abstract class ObserverableRunnable implements Runnable {

    protected LifecycleListener listener;

    public ObserverableRunnable(LifecycleListener listener) {
        this.listener = listener;
    }

    protected void notifyChange(final RunnableEvent runnableEvent) {
        listener.onEvent(runnableEvent);

    }

    public enum RunnableState {
        RUNNING, ERROR, DONE;
    }

    public enum Test{
        ERROR(0,"a"),
        success(1,"b");

        private int code;
        private String value;

        Test(int code, String value) {
            this.code = code;
            this.value = value;
        }
    }

    public static void main(String[] args) {
//        System.out.println(RunnableState.RUNNING);
//        System.out.println(Test.success.hashCode());
        System.out.println(Test.valueOf("ERROR"));
        System.out.println(Test.ERROR.equals("ERROR"));
        System.out.println(Test.valueOf("ERROR")==Test.ERROR);
//        System.out.println(Test.valueOf("error"));
        System.out.println(Test.ERROR.code);
//        System.out.println(Test.ERROR.getCode());
        System.out.println(Test.ERROR.value);
//        System.out.println(Test.ERROR.getValue());

//        List<String> list = Arrays.asList("1", "2", "3");

        List<String> list = new ArrayList<>();
        Collections.addAll(list, "1", "2", "3");
        System.out.println(list);
        list.stream().forEach(System.out::println);

        for (String s : list) {
            System.out.println(s);
        }

        list.add("4");
        list.remove(2);
        System.out.println(list);



    }

    public static class RunnableEvent {
        private final RunnableState state;
        private final Thread thread;
        private final Throwable cause;

        public RunnableState getState() {
            return state;
        }

        public Thread getThread() {
            return thread;
        }

        public Throwable getCause() {
            return cause;
        }

        public RunnableEvent(RunnableState state, Thread thread, Throwable cause) {
            this.state = state;
            this.thread = thread;
            this.cause = cause;
        }
    }
}
